package com.liuguang.framework.onActivityForResult;

import android.app.Activity;
import android.content.Intent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OnActivityForResultUtils {
    public static Map<Integer, List<OnActivityForResultCallback>> resultMap = new HashMap();

    public static void startActivityForResult(Activity activity, Integer num, Intent intent, OnActivityForResultCallback onActivityForResultCallback) {
        if (((List) resultMap.get(num)) == null) {
            resultMap.put(num, new ArrayList());
        }
        ((List) resultMap.get(num)).add(0, onActivityForResultCallback);
        activity.startActivityForResult(intent, num.intValue());
    }

    public static void onActivityResult(int i, int i2, Intent intent) {
        List<OnActivityForResultCallback> list = (List) resultMap.get(Integer.valueOf(i));
        if (list != null) {
            for (OnActivityForResultCallback onActivityForResultCallback : list) {
                if (i2 == 0) {
                    onActivityForResultCallback.cancel(intent);
                } else {
                    onActivityForResultCallback.success(Integer.valueOf(i2), intent);
                }
                onActivityForResultCallback.result(Integer.valueOf(i2), intent);
            }
            list.clear();
        }
    }
}
